﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace Argos.Windows.Forms
{
	public partial class IPAddressEditorDialog: Form
	{
		public IPAddressEditorDialog()
		{
			InitializeComponent();
		}


		private IPAddress _SelectedAddress;

		public IPAddress SelectedAddress
		{
			get { return _SelectedAddress; }
			set
			{
				_SelectedAddress = value;
				if (null != value)
				{
					this.IPAddressTextbox.Text = value.ToString();
				}
			}
		}

		private void IPAddressTextbox_Validating(object sender, CancelEventArgs e)
		{
			IPAddress addr;

			if (!IPAddress.TryParse(this.IPAddressTextbox.Text, out addr))
			{
				MessageBox.Show(this, "Unable to parse the specified IP address. Please verify.", "Invalid IP Address", MessageBoxButtons.OK);
				e.Cancel = true;

				return;
			}

			this.SelectedAddress = addr;
		}
	}
}
